package com.test3;

/****
 * 输入线程资源
 *
 */
public class IntThrad extends Thread {
	public Res res;

	public IntThrad(Res res) {
		this.res = res;
	}

	@Override
	public void run() {
		int count = 0;
		while (true) {
			synchronized (res) {
				if (res.flag) {
					try {
					   // 当前线程变为等待，但是可以释放锁
						res.wait();
					} catch (Exception e) {

					}
				}
				if (count == 0) {
					res.userName = "小军";
					res.userSex = "男";
				} else {
					res.userName = "小红";
					res.userSex = "女";
				}
				count = (count + 1) % 2;
				res.flag = true;
				// 唤醒当前线程
				res.notify();
			}

		}
	}
}
